package com.demo.springcloud.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import java.util.UUID;

/**
 * @author chenyuan
 * @date 2020/12/17 10:47
 */
@EnableBinding(Source.class) //定义消息的推送管道, 绑定 信道（Channel）和 Exchange
public class MessageProviderImpl implements IMessageProvider {
	@Autowired
	private MessageChannel output; // 消息发送管道

	@Override
	public String send() {
		// 简单的消息
		String serial = UUID.randomUUID().toString();
		output.send(MessageBuilder.withPayload(serial).build());
		System.out.println("*****serial: " + serial);
		return null;
	}
}
